<?php
/**
 * Implements a MySQL INSERT query
 */
class MySQLInsert extends SQLInsert {
	private $objOptions;
	private $objOnDuplicateKeyUpdates;

	/**
	 * Sets options for query.
	 *
	 * @param SQLOptionsClause $objSQLOptions
	 * @return SQLSelect
	 */
	public function setOptions($objSQLOptionsClause) {
		$this->objOptions = $objSQLOptionsClause;
		return $this;
	}
	
	/**
	 * Sets ON DUPLICATE KEY UPDATE clause for query.
	 * 
	 * @param SQLUpdatesClause $objSQLUpdatesClause
	 * @return MySQLInsert
	 */
	public function setOnDuplicateKeyUpdates($objSQLUpdatesClause) {
		$this->objOnDuplicateKeyUpdates = $objSQLUpdatesClause;
		return $this;
	}
	
	/**
	 * Outputs query as string.
	 * 
	 * (non-PHPdoc)
	 * @see SQLInsert::toString()
	 */
	public function toString() {
		return "".
		"INSERT ".($this->objOptions!=null?$this->objOptions->toString():"")." INTO ".$this->strTableName		."\r\n".
		"(".($this->objColumns?$this->objColumns->toString():$this->objInserts->getColumns()).")"				."\r\n".
		"VALUES"																								."\r\n".
		$this->objInserts->getRows($this->objColumns?$this->objColumns->toArray():array())						."\r\n".
		($this->objOnDuplicateKeyUpdates?"ON DUPLICATE KEY UPDATE ".$this->objOnDuplicateKeyUpdates->toString():"");
	}
}